﻿using System;
using System.IO;
using System.Text;
using ClieOp;
using NUnit.Framework;

namespace ClieOpTest
{
    [TestFixture]
    internal class ParseBatchTest
    {
        [Test]
        public void ParseBatchTest1()
        {
            var batch1 = new Batch(786892692, new DateTime(2000, 1, 1), "Roel van der Steen");
            batch1.AddVasteomschrijving("foo bar");
            batch1.AddPost(new Post(12.34m, 786892692, "Roel van der Steen", "abcdefghij"));
            batch1.AddPost(new Post(12.34m, 786892692, "Roel van der Steen", ""));
            var memorystream = new MemoryStream(Encoding.Default.GetBytes(batch1.ToString()));
            var reader = new ClieOpReader(memorystream);
            Batch batch2 = Batch.Parse(reader);
            Assert.AreEqual(batch1.Aantalposten, batch2.Aantalposten);
            Assert.AreEqual(batch1.Vasteomschrijvingen[0], batch2.Vasteomschrijvingen[0]);
        }

        [Test, ExpectedException(ExpectedMessage = "Aantalposten in ClieOp file does not match the actual Aantalposten. Expected: 1, actual: 2.")]
        public void ParseBatchTest2()
        {
            const string clieOpString =
                "0010B1007868926920000EUR                          \r\n0020Afoo bar                                      \r\n"
                + "0030B1010100Roel van der Steen                 P  \r\n0100A100100000000123407868926920786892692         \r\n"
                + "0150Aabcdefghij                                   \r\n0100A100100000000123407868926920786892692         \r\n"
                + "0150A                                             \r\n9990A00000000000000246831475707680000001          \r\n";
            var memorystream = new MemoryStream(Encoding.Default.GetBytes(clieOpString));
            var reader = new ClieOpReader(memorystream);
            Batch.Parse(reader);
        }
    }
}